<!DOCTYPE html>
<html>
<head>
	{include file="common_header" /}
	{include file="common_top" /}
	<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header">添加分类</div>
      <div class="layui-card-body" style="padding: 15px;">
        <form class="layui-form" action="" lay-filter="component-form-group">

          
          <div class="layui-form-item">
            <label class="layui-form-label">公告标题</label>
            <div class="layui-input-block">
              <input type="text" name="title" id="title"   placeholder="公告标题" class="layui-input" value="{$info['n_title']}">
            </div>
          </div>
		  
		  <div class="layui-form-item">
            <label class="layui-form-label">公告内容</label>
            <div class="layui-input-block">
              <script id="editor" type="text/plain" style="width:100%;height:300px;"></script>
            </div>
          </div>
		  
			<div class="layui-form-item">
				<label class="layui-form-label">所属分类</label>
				<div class="layui-input-block">
				  <select name="nt_id" id="nt_id">
					{volist name="noticetype" id="vo"}
					<option value="{$vo.nt_id}" {if $info['nt_id']==$vo.nt_id}selected="selected"{/if}>{$vo.nt_title}</option>
					{/volist}
				  </select>
				</div>
			</div>
		  
		  <div class="layui-form-item">
            <label class="layui-form-label">公告浏览量</label>
            <div class="layui-input-block">
              <input type="text" name="read" id="read"   placeholder="公告浏览量" class="layui-input" value="{$info['n_read']}">
            </div>
          </div>
		  

          <div class="layui-form-item">
            <label class="layui-form-label">公告状态</label>
            <div class="layui-input-block">
              <input type="radio" name="status" value="1" title="启用" {if $info['n_status']==1}checked=""{/if}>
              <input type="radio" name="status" value="2" title="禁用" {if $info['n_status']==2}checked=""{/if}>
            </div>
          </div>       
          <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
              <div class="layui-footer" style="left: 0;">
                <div class="layui-btn sub">立即提交</div>
                <button type="reset" class="layui-btn layui-btn-primary ">重置</button>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
{include file="common_footer" /} 
<script>
var ue = UE.getEditor('editor');
$(document).ready(function () {
    ue.ready(function () {
        ue.setContent('{$info['n_content']}');
    });
});


$(".sub").click(function(){
	//if(!$(".btn").hasClass("sub")){return false;}
	
	var nt_id        = $("#nt_id").val();
	var title        = $("#title").val();
	var editor = UE.getEditor('editor').getContent();
	var read      = $("#read").val();
	var status       = $("input[name='status']:checked").val();
	

	if(nt_id == ""){
		show_error("所属分类不能为空");
		return false
	}

	if(title == ""){
		show_error("公告标题不能为空");
		return false
	}
	
	if(read == ""){
		read = 0;
	}
	
	

	$.ajax({
		type:"POST",
		url:"{:url('notice/edit')}",
		dataType:"json",
		data:{
			id:{$info['n_id']},
			nt_id:nt_id,
			title:title,
			status:status,
			editor:editor,
			read:read,
		},
		success:function(res){
			if(res.status == "success"){
				show_toast_callurl(res.data,"{:url('notice/index')}","success");
			}else{
				show_error(res.data);
			}
		},
		error:function(jqXHR){
			console.log("Error: "+jqXHR.status);
		},
	});
	
});
</script>
</body>
</html>